
/*****************************************************************/
/*     dlg_input.cpp     Input Dialog Box & Function (Win32)     */
/*                       By: Josh Fiorio                         */
/*****************************************************************/

#include "dlg_input.h"

BOOL CALLBACK INPUT_DLG_Func(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
	switch (message)
	{
	case WM_INITDIALOG:
		SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(MAIN_ICON)));
		SetDlgItemText(hwnd, INFORM_BOX, (LPCSTR) lparam);
		return true;
	case WM_CLOSE:
		{
			//declare vars for getting the val
			int retval=0;
			BOOL istext=false;

			//get the val
			//retval=GetDlgItemInt(hwnd, TEXT_CHANGE, &istext, false);
			if (!istext)
			{
				//see if we can convert it to hex
				char hex[10]="";
				char *pEnd;
				GetDlgItemText(hwnd, TEXT_CHANGE, hex, 10);

				//if we can't, return false
				if ((retval = strtol(hex, &pEnd, 16)) == 0)
					EndDialog(hwnd, -1);
				//end if
			}	//end if

			//Return what we have to
			EndDialog(hwnd, retval);
			break;
		}
	case WM_COMMAND:
		if (LOWORD(wparam) == IDOK)
			SendMessage(hwnd, WM_CLOSE, 0, 0);
		if (LOWORD(wparam) == IDCANCEL)
			EndDialog(hwnd, -1);
		break;
	default:
		return false;
	}	//end switch

	return true;
}	//end of func.

int InputBox(char *t1)
{
	int ibox;

	ibox=DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(INPUT_DLG), NULL, 
		INPUT_DLG_Func, (LPARAM) t1);

	return ibox;
}	//end of func.

